﻿namespace Core.Domain.ValueObjects;

public record UserLockout
{
    public bool IsLocked => LockoutEnd.HasValue && LockoutEnd.Value > DateTimeOffset.UtcNow;
    public DateTimeOffset? LockoutEnd { get; private init; }
    public int? AccessFailedCount { get; private init; }

    public static UserLockout NotLocked() => new() { LockoutEnd = null, AccessFailedCount = 0 };

    public static UserLockout LockedUntil(DateTimeOffset end) => new() { LockoutEnd = end };

    public UserLockout IncrementFailure()
    {
        return this with { AccessFailedCount = AccessFailedCount + 1 };
    }
}
